#pragma once
#include"stack.h"
void Stack::Push(const int x)
{
	if (top == capacity)
	{
		int newcapacity = capacity == 0 ? 4 : 2 * capacity;
		int* tmp = (int*)realloc(a, sizeof(int) * newcapacity);
		if (tmp == nullptr)
		{
			perror("");
			return;
		}
		a = tmp;
		capacity = newcapacity;
	}
	a[top] = x;
	top++;
}
void Stack::Pop()
{
	assert(top > 0);
	top--;
}
int Stack:: Top()
{
	assert(top > 0);
	return a[top - 1];
}
int Stack::Size()
{
	return top;
}
bool Stack::Empty()
{
	return top == 0;
}
void Stack::Print()
{
	while (!Empty())
	{
		int t = Top();
		printf("%d ", t);
		Pop();
	}
}